// Author: Domien Nowicki

#ifndef WORLDEDITORWIDGET_H
#define WORLDEDITORWIDGET_H

#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QCursor>
#include "World.h"
#include "MapWidget.h"
#include "TextureManagerView.h"
#include "ToolboxWidget.h"
#include "TextureManagerDialog.h"
#include "DefaultTextureWidget.h"
#include "CameraWidget.h"


class WorldEditorWidget: public QWidget, public World
{
	Q_OBJECT

	public:
		WorldEditorWidget(QWidget *parent=0);
		virtual ~WorldEditorWidget();

		virtual void Reset();
		virtual void LoadFromFile(const std::string& fileName);
		virtual void PlaceCamera(const Vector& pos, const Scalar& angle);
		virtual void RemoveCamera();
	signals:
		void changed();

	public slots:
		void slotChangeDefaultTexture(DefaultTextureWidget::DefaultTexture texture);

	private slots:
		void slotCellClicked(unsigned int mapX, unsigned int mapY);
		void slotCellSideClicked(unsigned int mapX, unsigned int mapY, Cell::Side side);
		void slotToolClicked(enum ToolboxWidget::Tool toolType);
		void slotTextureListClicked();
		void slotAddTexture();
		void slotAddSolidTexture();
		void slotRemoveTexture(unsigned int tindex);
		void slotCameraClicked();
		void slotCameraRotated(const Scalar& angle);
		void slotChangeUserColor(unsigned int tindex, const Pixel& userColor);
		

	protected:
		virtual void SetChanged();
		virtual void SetUnchanged();


	private:
		MapWidget *GetMapWidget();
		void UpdateDefaultTextures();
		void ResetSelectedTexture();
		void SetupWidget();


		CameraWidget *cameraWidget;
		ToolboxWidget *toolboxWidget;
		DefaultTextureWidget *defaultTextureWidget;
		TextureManagerDialog *textureDialog;

		QVBoxLayout *vboxLayout;
		QHBoxLayout *hboxLayout;

		QCursor textureCursor, eraserCursor, wallCursor, cameraCursor;

		unsigned int currentTextureIndex;
};

#endif //WORLDEDITORWIDGET_H

